package com.magicsoft.share.presenter.my;

import com.magicsoft.share.base.BasePresenter;
import com.magicsoft.share.bean.my.ArticleList;
import com.magicsoft.share.constant.APIService;
import com.magicsoft.share.constant.SPKey;
import com.magicsoft.share.rx_retrofit_network.location.retrofit.RetrofitUtil;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.LoadingTransformer;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.NetWorkTransformer;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.SimpleObserver;
import com.magicsoft.share.utils.SPUtils;
import com.magicsoft.share.view.my.ICollectView;

/**
 * Created by lyf on 2017/11/22/022.
 */

public class CollectPresenter extends BasePresenter<ICollectView> {

    public void myCollection(int pageNum, int pageSize) {
        RetrofitUtil.getApi(APIService.class).myCollection(SPUtils.getInstance().getString(SPKey.TOKEN), SPUtils.getInstance().getLong(SPKey.ID),
                pageNum, pageSize)
                .compose(new NetWorkTransformer<ArticleList>())
                .compose(new LoadingTransformer<ArticleList>(mContext))
                .subscribe(new SimpleObserver<ArticleList>(mCompositeDisposable) {
                    @Override
                    public void call(ArticleList articleList) {
                        getView().myCollectionSuccess(articleList);
                    }

                    @Override
                    public void showErrorMsg(Throwable e, String errorMsg) {
                        super.showErrorMsg(e, errorMsg);
                        getView().myCollectionFail();
                    }
                });
    }
}
